import { ref,reactive } from 'vue'
import { defineStore } from 'pinia'
import { getinfo } from '@/api/manager'
import { useUserStore } from './user'
export const usePageStore = defineStore('zpage', () => {
    // 侧边宽度
    const asideWidth = ref("250px")
    // 菜单
    const menus = ref([])
    // 权限
    const ruleNames = ref([])
    // 展开/缩起侧边
    const handleAsideWidth = () => {
       asideWidth.value = asideWidth.value == "250px" ? "60px" : "250px"
    }
    const setMenus = (obj) => {
        menus.value = obj
    }
    const setRulenames = (RuleNames) => {
        console.log('设置规则',RuleNames)
        ruleNames.value = RuleNames      
    }
    const getInfo = () => {   
        return new Promise((resolve,reject)=>{
            const userStore = useUserStore()
            console.log(userStore.user[0].id)
            getinfo(userStore.user[0].id).then(res=>{
                setMenus(res.menus)           
                setRulenames(res.ruleNames)
                resolve(res)
            }).catch(err=>reject(err))
        })     
    }
   
    return {
        asideWidth,
        menus,
        ruleNames,
        handleAsideWidth,
        setMenus,
        setRulenames,
        getInfo
    }
}
,{
    persist: false,
  }
)